<?php

namespace app\admin\service;

use think\facade\Cache;
use app\admin\Model\Administrator as AdministratorModel;

class Administrator
{
    /**
     * 是否已经登录
     * @return boolean
     */
    public static function isLogin(): bool
    {
        return static::getUserId() > 0;
    }

    /**
     * 获取后台用户ID
     * @return integer
     */
    public static function getUserId(): int
    {
        return intval(session('admins_id'));
    }

    public static function info()
    {
        $info = session('admins_'.session('admins_id'));

        if (! $info) {
            $info = AdministratorModel::find(session('admins_id'));
            session('admins_'.session('admins_id'), $info);
        }

        return $info;
    }

}